package com.lanswon.qzsmk.controller.inventoryManageController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;
import com.lanswon.qzsmk.vo.ApplyBatchInfo;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfBatchRequiredByEmp")
public class InventoryMagOfBatchRequiredByEmpController {
	
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfBatchRequiredByEmpController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	
	@RequiresPermissions("inventoryMagOfBatchRequiredByEmp:index")
	@RequestMapping(name = "柜员领用批量卡出库,inventoryMagOfBatchRequiredByEmp:index",value = "/receiveFinishedCardByEmp", method = { RequestMethod.POST, RequestMethod.GET })
	public String receiveFinishedCardByEmp(HttpServletRequest request) {
		
		return "EmpReceiveBatchCard";
	}
	
	@RequiresPermissions("inventoryMagOfBatchRequiredByEmp:queryBatchApplyRecords")
	@RequestMapping(name = "加载批次信息,inventoryMagOfBatchRequiredByEmp:queryBatchApplyRecords",value="/queryBatchApplyRecords",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryBatchApplyRecords(HttpServletRequest request) throws Exception{
		List<ApplyBatchInfo> applyBatchInfo = ims.queryBatchApplyRecordsByEmpReceive(request);
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("applyBatchInfo", applyBatchInfo);

		return map;
	}
	
	@RequiresPermissions("inventoryMagOfBatchRequiredByEmp:receiveByEmpRegister")
	@RequestMapping(name = "打印清单,inventoryMagOfBatchRequiredByEmp:receiveByEmpRegister",value="/receiveByEmpRegister",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> receiveByEmpRegister(String[] empReceivedInfoChecked,HttpServletRequest request) throws Exception{
		Map<String, Object> rMap = null;
		String receiveEmpNoByInventory = request.getParameter("receiveEmpNoByInventory");
		rMap = ims.batchInfoByEmpRegister(empReceivedInfoChecked,receiveEmpNoByInventory);

		Map<String, Object> map = new HashMap<String,Object>();
		Map<String,Object> pramMap = new HashMap<String,Object>();
		pramMap.put("applyType", rMap.get("credential_type"));
		map.put("ipAddress", rMap.get("ipAddress"));
		map.put("storageNo", rMap.get("storageNo"));
		map.put("max", "true");
		map.put("title", rMap.get("title"));
		map.put("rel", "receiveTask");
		map.put("statusCode", "200");
		map.put("message", "批量成品领卡成功");
		map.put("param", pramMap);
		map.put("url", "printCredentials/toStoragePdfView");
		
		map.put("jumpToTile", "柜员领用批量成品卡片");
		map.put("jumpToTabid", "receiveFinishedCardByEmp");
		map.put("jumpToUrl", "inventoryMagOfBatchRequiredByEmp/receiveFinishedCardByEmp");
		return map;
	}	
}
